import { DEFAULT_HEALTH } from '../consts/game';
import { defineStore } from 'pinia';

// import Sword from '~/game/models/Sword';

type State = {
  health: number;
  money: number;
  owned: string[];
  // sword?: Sword;
};

type Getter = any;

type Action = {
  buy(id: string, money: number): void;
  addHealth(): void;
  // setSword: (sword: Sword) => void;
};

export const useGlobalStore = defineStore<string, State, Getter, Action>(
  'ninjia-global',
  {
    state: () => {
      return {
        health: DEFAULT_HEALTH,
        money: 0, // 拥有的金币
        owned: ['Default'], // 拥有的物品 id 列表
      };
    },
    actions: {
      // 购买物品
      buy(id: string, money: number) {
        this.money = money;
        this.owned.push(id);
      },
      addHealth() {
        this.health++;
      },
      // setSword(sword) {
      //   this.sword = sword;
      // },
    },
    persist: {
      storage: localStorage,
    },
  },
);
